package com.donger.common.jobs.config;


import com.xxl.job.core.executor.impl.XxlJobSpringExecutor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;


@Slf4j
@ComponentScan("com.donger.common.jobs")
public class JobAgentAutoConfiguration {

    @Autowired
    private JobProperties jobProperties;


    @Bean(initMethod = "start", destroyMethod = "destroy")
    public XxlJobSpringExecutor xxlJobExecutor() {
        log.info(">>>>>>>>>>> xxl-job config init.");
        XxlJobSpringExecutor xxlJobSpringExecutor = new XxlJobSpringExecutor();
        xxlJobSpringExecutor.setAdminAddresses(jobProperties.getAdmin().getAddresses());
        xxlJobSpringExecutor.setIp(jobProperties.getExecutor().getIp());
        xxlJobSpringExecutor.setAppname(jobProperties.getExecutor().getAppname());
        xxlJobSpringExecutor.setPort(jobProperties.getExecutor().getPort());
        xxlJobSpringExecutor.setAccessToken(jobProperties.getExecutor().getAccessToken());
        xxlJobSpringExecutor.setLogPath(jobProperties.getExecutor().getLogPath());
        xxlJobSpringExecutor.setLogRetentionDays(jobProperties.getExecutor().getLogRetentionDays());
        return xxlJobSpringExecutor;
    }

}
